#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1;
const int M = 1e9 + 7;

int t;
ll n, m, k;

bool check() {
    if (m < n - 1) return false;
    if (m > n * (n - 1) / 2) return false;
    if (n == 1) return k > 1;

    if (m == n * (n - 1) / 2) return k > 2;
    return k > 3;
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> m >> k;
        puts(check() ? "YES" : "NO");
    }
    return 0;
}